home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 05 - 1989 / 05.08 Aug 89 / Jorg's Code / matrix.f < prev    next >
Encoding:
Text File  |  1989-06-23  |  3.5 KB  |  164 lines  |  [TEXT/MPS ]

  1. !!S Main
  2.     program matrix
  3.     
  4.     implicit none
  5.     
  6.     integer i,j,ticks1,ticks2
  7.     extended a(50,50), b(50,50), c(50,50)
  8.     extended time1,time2
  9.     
  10.     integer ticks
  11.     
  12.     type *,'Matrix multiplication benchmark'
  13.     type *,'-------------------------------'
  14.     type *
  15.     type *,'This program compares the number crunching power'
  16.     type *,'of some of the popular MPW compilers.'
  17.     type *,'Written under MPW 3.0 by J. Langowski / MacTutor 1989'
  18.     type *
  19.     type *,'Setting up 50x50 matrices...'
  20.  
  21.     ticks1 = ticks()
  22.     
  23.     do i=1,50
  24.         do j=1,50
  25.             a(i,j) = (i-1) + j-1
  26.             b(j,i) = a(i,j)
  27.         end do
  28.     end do
  29.     
  30.     ticks2 = ticks()
  31.     time1 = (ticks2-ticks1)/60.    
  32.     type *
  33.     write (6,'(f8.4,'' seconds for setting up matrices'')') time1
  34.     
  35.     ticks1 = ticks()
  36.     call mat_mult_for3(c,50,a,50,b,50,50,50,50)
  37.     
  38.     ticks2 = ticks()
  39.     time1 = (ticks2-ticks1)/60.    
  40.     type *
  41.     write (6,'(f8.4,'' seconds for multiplying matrices'',
  42.      *    '' using FORTRAN routine, opt=3'')') time1
  43.     type *,'c(25,25) = ',c(25,25)
  44.     
  45.     ticks1 = ticks()
  46.     call mat_mult_for(c,50,a,50,b,50,50,50,50)
  47.     
  48.     ticks2 = ticks()
  49.     time1 = (ticks2-ticks1)/60.    
  50.     type *
  51.     write (6,'(f8.4,'' seconds for multiplying matrices'',
  52.      *    '' using FORTRAN routine, opt=0'')') time1
  53.     type *,'c(25,25) = ',c(25,25)
  54.  
  55.     ticks1 = ticks()
  56.     call mat_mult_for1(c,50,a,50,b,50,50,50,50)
  57.     
  58.     ticks2 = ticks()
  59.     time1 = (ticks2-ticks1)/60.    
  60.     type *
  61.     write (6,'(f8.4,'' seconds for multiplying matrices'',
  62.      *    '' using FORTRAN routine, hand-optimized'')') time1
  63.     type *,'c(25,25) = ',c(25,25)
  64.     
  65.     ticks1 = ticks()
  66.     call mat_mul_pas(c,%val(50),a,%val(50),b,%val(50),%val(50),%val(50),%val(50))
  67.     
  68.     ticks2 = ticks()
  69.     time1 = (ticks2-ticks1)/60.    
  70.     type *
  71.     write (6,'(f8.4,'' seconds for multiplying matrices'',
  72.      *    '' using PASCAL routine'')') time1
  73.     type *,'c(25,25) = ',c(25,25)
  74.     
  75.     ticks1 = ticks()
  76.     call mat_mul_pas_opt(c,%val(50),a,%val(50),b,%val(50),%val(50),%val(50),%val(50))
  77.     
  78.     ticks2 = ticks()
  79.     time1 = (ticks2-ticks1)/60.    
  80.     type *
  81.     write (6,'(f8.4,'' seconds for multiplying matrices'',
  82.      *    '' using PASCAL routine, hand-optimized'')') time1
  83.     type *,'c(25,25) = ',c(25,25)
  84.     
  85.     ticks1 = ticks()
  86.     call mat_mul_c(c,%val(50),a,%val(50),b,%val(50),%val(50),%val(50),%val(50))
  87.     
  88.     ticks2 = ticks()
  89.     time1 = (ticks2-ticks1)/60.    
  90.     type *
  91.     write (6,'(f8.4,'' seconds for multiplying matrices'',
  92.      *    '' using C routine'')') time1
  93.     type *,'c(25,25) = ',c(25,25)
  94.     
  95.     ticks1 = ticks()
  96.     call mat_mul_c_opt(c,%val(50),a,%val(50),b,%val(50),%val(50),%val(50),%val(50))
  97.     
  98.     ticks2 = ticks()
  99.     time1 = (ticks2-ticks1)/60.    
  100.     type *
  101.     write (6,'(f8.4,'' seconds for multiplying matrices'',
  102.      *    '' using C routine, hand-optimized'')') time1
  103.     type *,'c(25,25) = ',c(25,25)
  104.     
  105.     end
  106.  
  107.  
  108. !!S Main
  109.     subroutine mat_mult_for3(c,nc,a,na,b,nb,n1,n2,n3)
  110. c sets c=a.b
  111. c na,nb,nc are first dimensions
  112. c n1 n2 n3 are problem dimensions
  113. c c is n1xn3
  114. c a    n1 n2
  115. c b    n2 n3
  116.     implicit none
  117.     
  118.     integer na,nb,nc,n1,n2,n3
  119.     integer*2 i,j,k
  120.     extended c(nc,n3),a(na,n2),b(nb,n3)
  121.     
  122.     do k=1,n3
  123.         do i=1,n1
  124.             c(i,k) = 0x0
  125.             do j=1,n2
  126.                 c(i,k) = c(i,k)+a(i,j)*b(j,k)
  127.             end do
  128.         end do
  129.     end do
  130.     return
  131.     end
  132.  
  133. !!S Main
  134.     subroutine mat_mult_for1(c,nc,a,na,b,nb,n1,n2,n3)
  135. c sets c=a.b
  136. c na,nb,nc are first dimensions
  137. c n1 n2 n3 are problem dimensions
  138. c c is n1xn3
  139. c a    n1 n2
  140. c b    n2 n3
  141.     implicit none
  142.     
  143.     integer na,nb,nc,n1,n2,n3
  144.     integer*2 i,j,k
  145.     extended c(nc,n3),a(na,n2),b(nb,n3)
  146.     extended sum 
  147.     
  148.     do k=1,n3
  149.         do i=1,n1
  150.             sum = 0x0
  151.             do j=1,n2
  152.                 sum = sum+a(i,j)*b(j,k)
  153.             end do
  154.             c(i,k) = sum
  155.         end do
  156.     end do
  157.     return
  158.     end
  159.  
  160. !!S Main
  161.     integer function ticks
  162.     ticks = long(362)
  163.     return
  164.     end